package com.taxsystem.yehao.activity;

import java.util.HashMap;
import java.util.List;

import com.taxsystem.yehao.jsonParser.HallWaitListJsonParser;
import com.taxsystem.yehao.tool.UrlHost;
import com.main.taxsystem.R;

import android.os.Bundle;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class HallWaitListActivity extends BaseListActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hall_wait);
		lv = (ListView) findViewById(R.id.hall_wait_list_view);
		progressBar = (ProgressBar) findViewById(R.id.hall_wait_list_progressBar);
		new Thread() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				HallWaitListActivity.this.setProcessBarVisible(true);
				simpleAdapter = new SimpleAdapter(HallWaitListActivity.this,getData(),R.layout.hall_wait_list_item,
						new String[] {"branchName","waitingCount","address","avgWaitTime","branchId"},  
					new int[] {R.id.hall_wait_list_branchName,R.id.hall_wait_list_waitCount,R.id.hall_wait_list_addr,R.id.hall_wait_list_avgWaitTime,R.id.hall_wait_list_branchId});
				HallWaitListActivity.this.setListAdapter();
				HallWaitListActivity.this.setProcessBarVisible(false);
			}
		}.start();
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				String branchId = ((TextView)view.findViewById(R.id.hall_wait_list_branchId)).getText().toString();
				Intent intent = new Intent(HallWaitListActivity.this,HallWaitDetailActivity.class);
				intent.putExtra("branchId", branchId);
				startActivity(intent);
			}
			
		});
//		Intent intent = new Intent(MainActivity.this,BranchListActivity.class);
//		startActivity(intent);
	}
	
	private List<HashMap<String,Object> > getData() {
		List <HashMap<String,Object >> list = HallWaitListJsonParser.parse(UrlHost.host+"/app/hallinfo/waitingbranchlist");
		return list;
	}
	
	
}
